using Mapster;
using SmartCommunity.Models;
using System.ComponentModel.DataAnnotations;

namespace SmartCommunity.Services.Community
{
    #region DTO属性映射
    /// <summary>
    /// 属性映射 AreaDtoRegister
    /// </summary>
    public class AreaDtoRegister : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            // config.ForType<AreaEntity, AreaDto>().Map(d => d.DeptName, s => s.Dept.DeptName, s => s.Dept != null);
        }
    }
    #endregion

    #region 数据传输对象 AreaDto
    /// <summary>
    /// 数据传输对象：小区
    /// </summary>
    public class AreaDto : BaseDto
    {
        /// <summary>
        /// 小区ID
        /// </summary>
        public Guid AreaId { get; set; }

        /// <summary>
        /// 小区名
        /// </summary>
        [Required(ErrorMessage = "小区名不能为空")]
        [StringLength(100, ErrorMessage = "小区名 长度不能超过 100.")]
        public string AreaName { get; set; } = string.Empty;

        /// <summary>
        /// 社区ID
        /// </summary>
        public Guid CommunityId { get; set; }

        /// <summary>
        /// 社区名称
        /// </summary>
        public string CommunityName { get; set; } = string.Empty;

        /// <summary>
        /// 小区地址
        /// </summary>
        [Required(ErrorMessage = "小区地址不能为空")]
        [StringLength(200, ErrorMessage = "小区地址 长度不能超过 200.")]
        public string AreaAddr { get; set; } = string.Empty;

        /// <summary>
        /// 建筑面积
        /// </summary>
        public decimal? BuildArea { get; set; }

        /// <summary>
        /// 绿化面积
        /// </summary>
        public decimal? PlantArea { get; set; }

        /// <summary>
        /// 占地面积(总面积)
        /// </summary>
        public decimal? TotalArea { get; set; }

        /// <summary>
        /// 排序号
        /// </summary>
        public int? SortNo { get; set; }

        /// <summary>
        /// 小区简介
        /// </summary>
        [StringLength(2000, ErrorMessage = "小区简介 长度不能超过 2000.")]
        public string? Remark { get; set; }

        /// <summary>
        /// 是否作废
        /// </summary>
        public bool Disabled { get; set; }

    }
    #endregion

    #region 数据查询对象
    /// <summary>
    /// 查询模型：小区
    /// </summary>
    public class AreaQuery : AbstractQuery<AreaEntity>
    {
        /// <summary>
        /// 主键ID多选查询
        /// </summary>
        public IEnumerable<Guid> Ids { get; set; } = [];

        public Guid? CommunityId { get; set; }


        /// <summary>
        /// 根据查询条件添加查询表达式
        /// </summary>
        protected override void MergeQueryExpression()
        {
            AddExpression(Ids.Any(), e => Ids.Contains(e.AreaId));
            AddExpression(CommunityId.HasValue, a => a.CommunityId == CommunityId!.Value);
             AddSearchExpression(s => o => o.CommunityName.Contains(s) || o.AreaName.Contains(s) || o.AreaAddr.Contains(s));
            // AddDateExpression(start => e => e.CreatedTime >= start, end => e => e.CreatedTime <= end);
        }
    }
    #endregion
}
